﻿using System;
using GalaSoft.MvvmLight.Threading;
using LiSAClient.Core.Viewmodel;

namespace LiSAClient.WpfClient.ViewModel.Projects.ArticleFeedback
{
    public class FeedbackItemViewModel : ContentViewModel
    {
        public EventHandler IsCheckedChangeEventHandler { get; set; }

        private bool isChecked;

        public bool IsChecked
        {
            get { return this.isChecked; }

            set
            {
                this.Set(() => this.IsChecked, ref this.isChecked, value);
                if ((this.IsCheckedChangeEventHandler != null && !this.isUnchecking) && value)
                {
                    if (this.DecisionText == null) this.DecisionText = string.Empty;
                    DispatcherHelper.CheckBeginInvokeOnUI(() => this.IsCheckedChangeEventHandler(this, null));
                }
            }
        }

        public string DecisionText { get; private set; }

        public Guid ArticleFeedbackID { get; private set; }


        private bool isUnchecking;
        public void UnCheck()
        {
            this.isUnchecking = true;
            this.IsChecked = false;
            this.isUnchecking = false;
        }

        public FeedbackItemViewModel(string decisionText, bool isChecked, Guid articleFeedbackID)
        {
            this.IsChecked = isChecked;
            this.ArticleFeedbackID = articleFeedbackID;
            this.DecisionText = decisionText;
        }
    }
}
